package com.eestimate.rest;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.log4j.Logger;

import com.eestimate.exceptions.ErrorCodeEnum;
import com.eestimate.valuesobjects.containers.BaseContainerVo;
import com.eestimate.valuesobjects.containers.EmployeeSessionContainer;

public class PrivateRestService extends BaseRestService{

	final static Logger log = Logger.getLogger(PrivateRestService.class);
	
	//private EmployeeService 		employeeService;
	
	@Context
	private HttpHeaders httpHeaders;
	
	@Context
	private Request httpRequest;
	
	@Context
	private ContainerRequestContext requestCtx;
	
	@Context
    private transient HttpServletRequest servletRequest;
	
	@POST
	@Path( "/employees/login" )
	@Produces( MediaType.APPLICATION_JSON )
	public BaseContainerVo login(String email, String password) {
		
		EmployeeSessionContainer empSessionContainer = new EmployeeSessionContainer();
		try{
			//EmployeeVo 	empVo 				= employeeService.fetchEmployee(email, password);
			//EmployeeSessionVo empSessionVo 	= employeeSessionService.createSession(empVo);
			//employeeService.changeLoginStatus(empVo.employeeId, true);
//			empSessionVo.employee.isLogin 	= "true";
//			
//			empSessionContainer.meta.code 	= HttpStatusCodes.OK;
//			empSessionContainer.data 		= empSessionVo;
			
			return empSessionContainer;
		}
//		catch(ServiceException exc){
//			exc.printStackTrace(System.err);
//			empSessionContainer.meta.code		= HttpStatusCodes.INVALID_REQUEST;
//			empSessionContainer.meta.error 		= HttpStatusStrings.INVALID_REQUEST;
//			empSessionContainer.meta.details	= ExceptionUtils.getRootCause(exc) == null ? exc.toString() : ExceptionUtils.getRootCause(exc).toString();
//			return empSessionContainer;
//		}
		catch(Exception exc){
			exc.printStackTrace(System.err);
			empSessionContainer.meta.code 		= ErrorCodeEnum.INTERNAL_SERVER_ERROR.getCode();
			empSessionContainer.meta.error 		= ErrorCodeEnum.INTERNAL_SERVER_ERROR.getMessage();
			empSessionContainer.meta.details	= ExceptionUtils.getRootCause(exc) == null ? exc.toString() : ExceptionUtils.getRootCause(exc).toString();
			return empSessionContainer;
		}
	}
	

	@POST
	@Path( "/employees/logout" )
	@Produces( MediaType.APPLICATION_JSON )
	public BaseContainerVo logout() {
		return null;
	}
	
		
	public void setHeaders(HttpHeaders headers) {
		this.httpHeaders = headers;
	}

	public void setRequest(Request request) {
		this.httpRequest = request;
	}

	public void setRequestCtx(ContainerRequestContext requestCtx) {
		this.requestCtx = requestCtx;
	}
	
	public void setServletRequest(HttpServletRequest servletRequest) {
		this.servletRequest = servletRequest;
	}

//	public void setEmployeeService(EmployeeService employeeService) {
//		this.employeeService = employeeService;
//	}

			  
}